{include file="common/mainHead"/}
<div class="admin-main fadeInUp animated" ng-app="hd" ng-controller="ctrl">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>{$title}</legend>
    </fieldset>
    <form class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-4">
                <input type="text" name="title" ng-model="field.title" lay-verify="required" placeholder="{:lang('pleaseEnter')}拍卖会标题" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">选择拍卖师</label>
            <div class="layui-input-4">
                <select name="auctor_id" ng-model="field.auctor_id" ng-options="v.admin_id as v.username for v in group" ng-selected="v.admin_id==field.auctor_id">

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">起拍时间</label>
            <div class="layui-input-4" id="box_starttime">
                <input type="datetime" ng-model="field.starttime" title="起拍时间" name="starttime" data-required="1" placeholder="请输入起拍时间" lay-verify="date" value="" class=" layui-input" onclick="layui.laydate({elem: this, istime: true,festival: true,format: 'YYYY-MM-DD hh:mm:ss'})">
            </div><div class="layui-form-mid layui-word-aux red">*必填                    </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">封面图片1</label>
            <div class="layui-input-block">
                <div class="site-demo-upload">
                    <img id="cltThumb1" src="__ADMIN__/images/tong.png">
                    <div class="site-demo-upbar">
                        <input type="file" name="pic1" lay-type="images" class="layui-upload-file" id="thumb1">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否发送短信</label>
            <div class="layui-input-4" id="box_status">
                <input ng-value=1 ng-model="field.status" name="status" id="status_1" value="1"  type="radio" class="ace" title="是">
                <div class="layui-unselect layui-form-radio layui-form-radioed">
                    <i class="layui-anim layui-icon"></i><span>是</span>
                </div>
                <input ng-value=0 ng-model="field.status" name="status" id="status_2" value="0" type="radio" class="ace" title="否">
                <div class="layui-unselect layui-form-radio">
                    <i class="layui-anim layui-icon"></i><span>否</span>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <a href="{:url('index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
            </div>
        </div>
    </form>
</div>
{include file="common/mainFoot"/}
<script src="__STATIC__/js/angular.min.js"></script>

<script>
    var m = angular.module('hd',[]);
    m.controller('ctrl',['$scope',function($scope) {
        $scope.field = '{$info}'!='null'?{$info}:{id:'',title:'',starttime:'',thumb1:'',status:''};
        if($scope.field.starttime != ''){
            $scope.field.starttime=getdate($scope.field.starttime);
        }
        $scope.group = {$auctorList};
        layui.use(['form', 'layer','laydate','upload'], function () {
            var form = layui.form(), layer = layui.layer,laydate = layui.laydate,upload = layui.upload;
            if($scope.field.thumb1){
                cltThumb1.src = "__PUBLIC__"+ $scope.field.thumb1;
            }
            upload({
                url: '{:url("UpFiles/upload")}',
                title: '封面图片',
                ext: 'jpg|png|gif', //那么，就只会支持这三种格式的上传。注意是用|分割。
                success: function(res, input){
                    if(input.name == 'pic1'){
                        cltThumb1.src = "__PUBLIC__"+res.url;
                        $scope.field.thumb1 = res.url;
                    }

                }
            });
            form.on('submit(submit)', function (data) {
                // 提交到方法 默认为本身
                data.field.id = $scope.field.id;
                data.field.thumb1=$scope.field.thumb1;
                $.post("", data.field, function (res) {
                    if (res.code > 0) {
                        layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                            location.href = res.url;
                        });
                    } else {
                        layer.msg(res.msg, {time: 1800, icon: 2});
                    }
                });
            })
        });
    }]);
    function getdate(date){
        var date = new Date(date*1000);//如果date为10位不需要乘1000
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
        var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
        var m = (date.getMinutes() <10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
        var s = (date.getSeconds() <10 ? '0' + date.getSeconds() : date.getSeconds());
        return Y+M+D+h+m+s;
    }
//    layui.use(['laydate'], function () {
//
//    });
</script>